home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DIRS.SWG / 0017_Setting a files path.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  1KB  |  54 lines

  1. {
  2. JON KENT
  3.  
  4. Here's one way to set a File's path "on the fly" using Typed Constants.
  5. }
  6.  
  7. Uses
  8.   Dos;
  9.  
  10. Const
  11.   TestFile1 : String = 'TEST1.DAT';
  12.   TestFile2 : String = 'DATA\TEST2.DAT';
  13. Var
  14.   CurrentPath : String;
  15.  
  16. Function FileStretch(SType : Byte; FileFullName : String) : String;
  17. Var
  18.   P : PathStr;
  19.   D : DirStr;
  20.   N : NameStr;
  21.   E : ExtStr;
  22. begin
  23.   P := FExpand(FileFullName);
  24.   FSplit(P, D, N, E);
  25.   if D[LENGTH(D)] = '\' then
  26.     D[0] := CHR(PRED(LENGTH(D)));
  27.   Case SType OF
  28.     1 :  FileStretch := D;
  29.     2 :  FileStretch := N + E;
  30.     3 :  FileStretch := D + '\' + N;
  31.     4 :  FileStretch := N;
  32.     else FileStretch := '';
  33.   end;
  34. end;
  35.  
  36. begin
  37.   CurrentPath := FileStretch(1,ParamStr(0));    { Get EXE's Path  }
  38.   TestFile1   := CurrentPath + '\' + TestFile1; { Set DAT Paths   }
  39.   TestFile2   := CurrentPath + '\' + TestFile2;
  40.  
  41.   {...}
  42.  
  43. end.
  44. {-----------------------------}
  45.  
  46. {  if CurrentPath = C:\WORK then
  47.  
  48.        TestFile1 = C:\WORK\TEST1.DAT
  49.        TestFile2 = C:\WORK\DATA\TEST2.DAT
  50.  
  51.   This works Really well when you want to store a Program's configuration
  52.   File or data Files in the same directory as the Program regardless its
  53.   location.
  54. }